<template>
    <span style="line-height: 21px;">
        <div v-if="alive_time_diff < 30" style="color:#19be6b">{{ alive_time_desc }}</div>
        <div v-else-if="alive_time_diff < 60" style="color:#f59f00">{{ alive_time_desc }}</div>
        <div v-else style="color:#eb0303">{{ alive_time_desc }}</div>
        <div style="font-size: 10px;color:#aaa;">{{ active_time }}</div>
    </span>
</template>

<script>
import { calculateTimeDifference, calculateTimeDifferenceDesc } from '@/utils/index.js';

export default {
    name: "ActiveDescTableCellValue",
    props: {
        active_time: String,
        now_time: String,
        default_desc: {
            type: String,
            default: '未上线'
        }
    },
    computed: {
        diff() {
            if (this.active_time) {
                return calculateTimeDifference(this.active_time, this.now_time);
            } else {
                return 10000000; // 设置一个很大的值，以便被认为不在线
            }
        },
        alive_time_desc() {
            // let diff = 0;
            // if (this.active_time) {
            //     diff = calculateTimeDifference(this.active_time, this.now_time);
            // } else {
            //     diff = 10000000; // 设置一个很大的值，以便被认为不在线
            // }
            if (this.active_time) {
                return calculateTimeDifferenceDesc(this.diff);
            } else {
                return this.default_desc;
            }
        },
        alive_time_diff() {
            return this.diff / 1000;
        }
    }

}
</script>